package com.ljkj.cordial.chat.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.github.yuweiguocn.library.greendao.MigrationHelper;
import com.nic.view.util.JLog;

import org.greenrobot.greendao.database.Database;

/**
 * @description:
 * @author: Panwei
 * @date: 2019/12/11 20:44
 */
public class DbOpenHelper extends DaoMaster.DevOpenHelper {

    public DbOpenHelper(Context context, String name) {
        super(context, name);
    }

    public DbOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }

    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        JLog.d("flag", "onUpgrade oldVersion=" + oldVersion + " newVersion=" + newVersion);
        /**
         *  将db传入, 将目录下的所有的Dao.类传入
         */
//        MigrationHelper.migrate(db, ChatTableBeanDao.class, FriendTableDao.class, GroupTableDao.class
//                , BusinessLeaveTableDao.class, GroupMemberTableDao.class, SysNoticeTableDao.class, LengthMessageTableDao.class
//                , UserTableBeanDao.class, AlbumTableBeanDao.class, ChatContentTableDao.class);
        MigrationHelper.migrate(db, new MigrationHelper.ReCreateAllTableListener() {
                    @Override
                    public void onCreateAllTables(Database db, boolean ifNotExists) {
                        DaoMaster.createAllTables(db, ifNotExists);
                    }

                    @Override
                    public void onDropAllTables(Database db, boolean ifExists) {
                        DaoMaster.dropAllTables(db, ifExists);
                    }
                }, ChatTableBeanDao.class, FriendTableDao.class, GroupTableDao.class
                , BusinessLeaveTableDao.class, GroupMemberTableDao.class, SysNoticeTableDao.class, LengthMessageTableDao.class
                , UserTableBeanDao.class, AlbumTableBeanDao.class, ChatContentTableDao.class);
    }
}
